const { log } = require('console');
const express = require('express');
const app = express();
const expressWs = require('express-ws')(app);
// const fs = require('fs');
app.use('/uploads', express.static(__dirname + '/uploads'))
// app.set('tokenKey', fs.readFileSync('./token.key'));
// app.set('secretKey', fs.readFileSync('./secret.key'));
app.use(require('cors')());
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(express.static('./'));

require('./dao/db')(app);
require('./routes')(app);
require('./webscoket')(app);
// 开启RTSP流服务 startVideoStreamServer
// const rtspStream = require('./utils/rtsp-stream')(app);
// const rtspPort = 8554;
// const wsPort = 8080;
// const rtspPath = '/stream';
// const wsPath = '/ws';
// const resolution = '640x480';
// const videoFilePath = 'C:\\Users\\胡永乐\\hVideo\\b\\test.mp4';
// rtspStream.startVideoStreamServer(expressWs, videoFilePath, {
//     rtspPort,
//     wsPort,
//     rtspPath,
//     wsPath,
//     resolution,
// }).then(() => {
//     console.log(`RTSP stream started on port ${rtspPort}`);
// }).catch(err => {
//     console.error(err);
// });

// const stream = require('./utils/rtsp-stream')(app);
// const name = 'camera_0';
// const rtspUrl = 'rtsp://admin:hyl102700@192.168.0.102:554/h265/ch1/main/av_stream';
// const wsPort = 9999;
// stream.startRTSPStream({
//     name: name,
//     streamUrl: rtspUrl,
//     wsPort: wsPort,
// })

// const onvif = require('./utils/onvif');
// const onvif2 = require('node-onvif');
// opteration();
// async function opteration() {
//     const { device, type, message, base, control } = await onvif.conn({
//         xaddr: 'http://192.168.0.102:81/onvif/device_service',
//         user: 'admin',
//         pass: 'hyl102700',
//     })
//     const token = base.getCurrentProfile()['token']
    // console.log((await base.getCurrentPostiton({ ProfileToken: token })));
    // console.log((await base.getStreamUri({ ProfileToken: token })));
    // console.log((await base.getSnapshotUri({ ProfileToken: token })));

// }


app.listen(3000, () => {
    console.log("App is listening：http://localhost:3000/")
})


